package Leetcode.LeetcodeDemo1;

import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;

public class LeetCode11 {
    public static void main(String[] args) {
            int[] arr={1,1};
        System.out.println(maxArea(arr));
    }
    public static int maxArea(int[] height){
        Nob[] nobs=new Nob[height.length];
        for (int i = 0; i < height.length; i++) {
            nobs[i]=new Nob(height[i],i);
        }
        PriorityQueue<Nob> maxHeight=new PriorityQueue<>(new Comparator<Nob>() {
            @Override
            public int compare(Nob o1, Nob o2) {
                return o2.height-o1.height;
            }
        });
        int max=0;
        HashSet<Nob> set=new HashSet<>();
        for (int i = 0; i < nobs.length; i++) {
            maxHeight.add(nobs[i]);
        }
        while(!maxHeight.isEmpty()){
            Nob nob1=maxHeight.poll();
            set.add(nob1);
            PriorityQueue<Nob> maxX=new PriorityQueue<>(new Comparator<Nob>() {
                @Override
                public int compare(Nob o1, Nob o2) {
                    return Math.abs(o2.x-nob1.x)-Math.abs(o1.x-nob1.x);
                }
            });
            for (int i = 0; i < nobs.length; i++) {
                if(!set.contains(nobs[i])){
                    maxX.add(nobs[i]);
                }
            }
            while(!maxX.isEmpty()){
                Nob nobTmp1=maxX.poll();
                int maxTmp=Math.min(nob1.height,nobTmp1.height)*Math.abs(nob1.x- nobTmp1.x);
                max=max>maxTmp?max:maxTmp;
            }
        }
        return max;
    }
    public static class Nob{
        public int height;
        public int x;
        public Nob(int height,int x){
            this.height=height;
            this.x=x;
        }
    }
}
